<template>
	<view style="padding:30rpx">
		<uni-section >
			<uni-forms ref="uniForm" :rules="rules" :model="formData" label-position="top" border labelWidth="140px">
				<uni-forms-item label="父亲血型" name="father">
					<uni-data-checkbox v-model="formData.father" :localdata="hemorrhagics" />
				</uni-forms-item>
				<uni-forms-item label="母亲血型" name="mother">
					<uni-data-checkbox v-model="formData.mother" :localdata="hemorrhagics" />
				</uni-forms-item>
			</uni-forms>
			<button class="uni-btn  uni-btn-radius" type="primary" @click="submit">计算</button>
		</uni-section>
		
		<uni-section title="预测结果" type="line" v-if="predictedBloodType" >
			<view style="padding: 35rpx;font-size: 40rpx;">
			  <view style="padding-top: 0rpx;">
			    <text>预测血型：</text>
			    <text style="font-weight: bold;">{{ predictedBloodType }}</text>
			  </view>
			</view>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				hemorrhagics:[{text: 'A',value:'A'},{text: 'B',value:'B'},{text: 'AB',value:'AB'},{text: 'O',value:'O'}],
				predictedBloodType:null,		//预计血型
				nohemorrhagic:null,     //不可能预计血型
				formData:{
					 
				},
				rules: {
					mother: {
						rules: [{
							required: true,
							errorMessage: '请选择母亲血型'
						}]
					},
					father: {
						rules: [{
							required: true,
							errorMessage: '请选择父亲血型'
						}]
					}
				}
			}
		},
		methods: {
		submit()
			{
				this.$refs.uniForm.validate().then(res => {
					 this.predictedBloodType = '';
					 this.nohemorrhagic = '';
					 this.calculate();
				}).catch(err => {
					console.log('err', err);
				})	
			},
			calculate() 
			{
				const father = this.formData.father;
				const mother = this.formData.mother;
				
				const fm = father +  mother;
				const predicted = fm.split('').sort().join('');
		
				
				if(predicted == 'AA')
				{
					this.predictedBloodType = "A型、O型";
				}
				else if(predicted == 'BB'){
					this.predictedBloodType = "B型、O型";
				}
				else if(predicted == 'AB'){
					this.predictedBloodType = "A型、B型、AB型、O型";
				}
				else if(predicted == 'AO'){
					this.predictedBloodType = "A型、O型";
				}
				else if(predicted == 'BO'){
					this.predictedBloodType = "B型、O型";
				}
				else if(predicted == 'OO'){
					this.predictedBloodType = "O型";
				}
				else if(predicted == 'AAB'){
					this.predictedBloodType = "A型、B型、AB型";
				}
				else if(predicted == 'ABB'){
					this.predictedBloodType = "A型、B型、AB型";
				}
				else if(predicted == 'ABO'){
					this.predictedBloodType = "A型、B型";
				}
				else if(predicted == 'AABB'){
					this.predictedBloodType = "A型、B型、AB型";
				}
				
			},
		}
	}
</script>

<style>

</style>
